<?php

use app\assets\ApiAsset;
use app\assets\LayerAsset;
use app\assets\TableAsset;
use app\widgets\LinkPager;
use app\widgets\ManagerTableOp;
use yii\helpers\Html;
use app\models\KeyMap;
use dosamigos\datepicker\DatePicker;
use yii\helpers\Url;
/**
 * @var $this yii\web\View
 * @var $profitList app\models\AgentProfit[]
 * @var $pagination yii\data\Pagination
 */

ApiAsset::register($this);
LayerAsset::register($this);
TableAsset::register($this);

$this->title = '代理商收益列表';
$this->params['breadcrumbs'][] = '财务管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<?php echo Html::beginForm('?', 'get', ['class'=>'form-inline']);?>
<div class="form-group">
    <label for="search_agent" class="sr-only">Agent</label>
    <?php echo Html::textInput('search_agent', Yii::$app->request->get('search_agent'), ['id'=>'search_agent', 'class'=>'form-control', 'placeholder'=>'搜索代理商', 'style' => 'width:120px;']);?>
</div>
<div class="form-group">
    <label for="search_status" class="sr-only">来源</label>
    <?php echo Html::dropDownList('search_source', Yii::$app->request->get('search_source'), KeyMap::getValues('source'), ['id' => 'search_source', 'class' => 'form-control', 'prompt' => '来源']);?>
</div>
<div class="form-group">
    <label for="time">起始时间</label>
    <?php echo DatePicker::widget([ 
        'name' => 'search_start_time', 
        'options' => ['placeholder' => '起始时间'], 
        'attribute' => 'time',
        'template' => '{addon}{input}',
        'value' => $search_start_time,
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true, 
        ] 
    ]); ?>
</div>
<div class="form-group">
    <label for="time">结束时间</label>
    <?php echo DatePicker::widget([ 
        'name' => 'search_end_time', 
        'options' => ['placeholder' => '结束时间'], 
        'attribute' => 'time',
        'template' => '{addon}{input}',
        'value' => $search_end_time,
        'clientOptions' => [ 
            'autoclose' => true, 
            'format' => 'yyyy-mm-dd',
            'todayHighlight' => true, 
        ] 
    ]); ?>
</div>
<div class="form-group">
    <button class="btn btn-primary btn-sm">搜索</button>
</div>
<?php echo Html::endForm();?>
<table class="table table-striped table-bordered table-hover">
    <thead>
    <tr>
        <th class="center">
            <label class="pos-rel">
                <input type="checkbox" class="ace" />
                <span class="lbl">编号</span>
            </label>
        </th>
        <th class="center">代理商</th>
        <th class="center">ICCID/MSISDN/IMSI</th>
        <th class="center">充值信息</th>
        <th class="center">套餐</th>
        <th class="center">收益金额</th>
        <th class="center">来源</th>
        <th class="center">收益类型</th>
		<th class="center">分佣类型</th>
        <th class="center">时间</th>
    </tr>
    </thead>

    <tbody>
    <?php foreach ($profitList as $profit) {?>
        <tr>
            <td class="center"><label class="pos-rel"><input type="checkbox" class="ace" value="<?php echo $profit->id;?>" /><span class="lbl"><?php echo $profit->id;?></span></label></td>
            <td class="center"><?php echo Html::a(Html::encode($profit->agent->username), ['/admin/user/agent-view', 'id' => $profit->agent_id]);?></td>
            <td class="center"><?php echo empty($profit->card->iccid) ? '----' : Html::encode($profit->card->iccid);
                echo '<br />';
                echo empty($profit->card->msisdn) ? '----' : Html::encode($profit->card->msisdn);
                echo '<br />';
                echo empty($profit->card->imsi) ? '----' : Html::encode($profit->card->imsi);?></td>
            <td class="center"><?php echo Html::a($profit->user_card_recharge_id, ['/admin/finance/recharge-view', 'id' => $profit->user_card_recharge_id]);?></td>
            <td class="center"><?php echo $profit->package->name;?></td>
            <td class="center"><?php echo $profit->money;?></td>
            <td class="center"><?php echo KeyMap::getValue('source',$profit->source);?></td>
            <td class="center"><?php echo KeyMap::getValue('profit_type',$profit->profit_type);?></td>
			<td class="center"><?php echo KeyMap::getValue('comm_type',$profit->comm_type);?></td>
            <td class="center"><?php echo Yii::$app->formatter->asDatetime($profit->create_time);?></td>
            
        </tr>
    <?php }?>
    </tbody>
</table>
<?php echo LinkPager::widget(['pagination' => $pagination]);?>
<script type="text/javascript">
    function deletelog(id) {
        if (!confirm('确定要删除吗？')) {
            return false;
        }
        $.getJSON('<?php echo Url::to(['/admin/finance/delete-profit']);?>', {'id':id}, function(json) {
            if (callback(json)) {
                layer.msg('删除成功', function () {window.location.reload();});
            }
        });
    }
</script>
